package com.example.reader.service;

import cn.hutool.core.date.DateUtil;
import com.example.reader.entity.Cart;
import com.example.reader.mapper.CartMapper;
import com.example.reader.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartService {
    @Autowired
    private CartMapper cartMapper;
    public void add(Cart cart){
        //获取到当前用户信息
        Integer userid= TokenUtils.getCurrentUser().getId();
        cart.setUserId(userid);
        cart.setTime(DateUtil.now());
        cartMapper.insert(cart);
    }


    public List<Cart> selectAll(Cart cart) {
        //查询自己的书单
        Integer userid = TokenUtils.getCurrentUser().getId();
        cart.setUserId(userid);
        return cartMapper.selectAll(cart);
    }

    //单个删除
    public void deletebyid(Integer id){
        cartMapper.deletebyid(id);
    }

    //批量删除
    public void deleteBatch(Integer[] ids) {
        cartMapper.deletebyids(ids);
    }


}
